package com.foreknow.demo2;

import javax.sound.midi.Soundbank;
import java.util.Scanner;

public class LoopExample {
    public static void main(String[] args) {
        boolean isSelect = true;
        String userInfoName = "";
        String userInfoPwd = "";
        int count = 3;
        Scanner input = new Scanner(System.in);
        while (isSelect){
            System.out.println("*****************欢迎进入*****************");
            System.out.println("1.注册\n2.登录\n3.抽奖");
            System.out.println("******************************************");
            System.out.println("请选择菜单");
            int menuNum = input.nextInt();
            switch (menuNum) {
                case 1:
                    System.out.println("【系统】： 注册");
                    System.out.println("请输入个人信息");
                    userInfoName = input.next();
                    userInfoPwd = input.next();
                    int cardNum = (int) (Math.random() * 10000);
                    System.out.printf("注册成功，请记住你的四位卡号%d\n",cardNum);
                    System.out.println("用户名:" + userInfoName + "密码" + userInfoPwd + "卡号" + cardNum);
                    break;
                case 2:
                    do {
                        System.out.println("【系统】： 登录");
                        System.out.println("请输入用户名密码");
                        String userNameLogin = input.next();
                        String userPwdLogin = input.next();
                        if (userNameLogin.equals(userInfoName) && userPwdLogin.equals(userInfoPwd)){
                            System.out.printf("恭喜您成功登录用户%s",userInfoName);
                            count = 0;
                        }else {
                            if (count == 0) {
                                System.out.println("次数已经用光，请返回系统重新操作");
                            }else {
                                count--;
                                System.out.printf("您还剩余%d次登录机会\n,请重新输入",count);
                            }
                        }
                    }while (count != 0);
                    break;
                case 3:
                    System.out.println("【系统】： 抽奖");
                    break;
            }
            System.out.println("是否继续（y/n）");
            String isContinue = input.next();
            if (isContinue.equals("y")) {
                isSelect  = true;
            } else {
                isSelect = false;
                System.out.println("系统退出，感谢使用！");
            }
        };

    }
}
